package edit;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;

import javax.swing.JButton;
import javax.swing.JPanel;

import view.grammardevelopment.editsemantics.ComponentPaletteScrollPane;

import components.Component;

public class FCSRightPanel extends JPanel
{
	private ComponentPaletteScrollPane cpScrollPane;
	private FCSRulePane fcsRule;
	private LeafPane lPane;
	private JButton deleteBtn;
	private Component comp;
	private String title;
	
	public FCSRightPanel(String title)
	{
		this.title = title;
		cpScrollPane = new ComponentPaletteScrollPane();
		fcsRule = new FCSRulePane(title);
		lPane = new LeafPane();
		createDeleteButton();
		
		add(fcsRule);
		add(deleteBtn);
		add(cpScrollPane);
		add(lPane);
	}

	private void createDeleteButton()
	{
		deleteBtn = new JButton("Delete Selected Component");
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		double width = screenSize.getWidth();
		double height = screenSize.getHeight();
		int palettewidth = (int)(width*0.4);
		int paletteheight = (int)(height*0.1);
		Dimension dimension = new Dimension(palettewidth,paletteheight);
		deleteBtn.setFont(new Font(this.getFont().getFontName(), Font.PLAIN, paletteheight/4));
		deleteBtn.setPreferredSize(dimension);
	}

	//Setters
	public void setComponent(Component comp){
		if(comp != null){
			this.comp = comp;
			if(comp.isLeaf()){
				lPane.setWordValues();
				lPane.enableComponents();
			}
			else
				lPane.disableComponents();	
		}
	}
		
	public void addDnDListenerForAllButtons(MouseAdapter mouseAdapter){
		cpScrollPane.addListenersForAllButtons(mouseAdapter);
	}
	
	public Component getComponent(){
		return comp;
	}
	
	//Delete Listener
	public void addDeleteBtnListener(ActionListener listener){
		deleteBtn.addActionListener(listener);
	}
	
	//CompPalette Listener
	public void addCompPaletteDragListener(MouseAdapter mouseAdapter){
		cpScrollPane.addListenersForAllButtons(mouseAdapter);
	}
	
}
